# -*- encoding: utf-8 -*-
#
# Copyright (C) 2008 Håvard Gulldahl.
#
# Licensed under the GNU Public License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.gnu.org/licenses/gpl-2.0.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

__author__ = u'<havard@gulldahl.no> Håvard Gulldahl'
__license__ = 'GPL v2'

import sys, logging
from PyQt4 import QtGui, QtCore
from gcontacts import contactsmodel
import gcontactsbase

class gcontactstrash(QtGui.QLabel):

  def dragEnterEvent(self, event):
    logging.debug('dragEnter')
    if not event.mimeData().hasFormat(contactsmodel.INTERNAL_MIMETYPE):
      return
    logging.debug('accepting')
    event.acceptProposedAction()

  def dropEvent(self, event):
    logging.debug('drop')
    if not event.mimeData().hasFormat(contactsmodel.INTERNAL_MIMETYPE):
      return
    logging.debug('accepting')
    event.acceptProposedAction()
    contactxml = event.mimeData().data(contactsmodel.INTERNAL_MIMETYPE)
    contact = gcontactsbase.ContactsFeedFromString(contactxml)
    logging.debug('delete entries: %s', [e.id.text for e in contact.entry])
    self.emit(QtCore.SIGNAL('deleteContacts(PyQt_PyObject)'), contact.entry)
